<?
include_once("./_common.php");

$apiKey = "AIzaSyBIbQfEpzHjRn9sRDNFramGCH8FM2h8UPk";
$messageData = "공지사항이 등록되었습니다.";

$headers = array('Content-Type:application/json ; charset=UTF-8', 'Authorization:key=AIzaSyBIbQfEpzHjRn9sRDNFramGCH8FM2h8UPk');

$sql = "SELECT reg_id
		  FROM gcm_table";

$rst = sql_query($sql);

$conidx=0;

$arr = array();
$arr['data'] = array();
$arr['data']['msg'] = $messageData;
$arr['registration_ids'] = array();

while($row = mysql_fetch_array($rst))
{
	$arr['registration_ids'][$conidx] = $row['reg_id'] ;
	$conidx++;
}

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($arr));

$response = curl_exec($ch);

echo $response;
curl_close($ch);


?>